<?php 
namespace plugins\sms_account\controller; 

use cmf\controller\PluginAdminBaseController; //引入此类

use plugins\sms_account\model\SmsAccountModel;
use plugins\sms_account\model\SmsAccountBuyModel;
use plugins\sms_account\model\SmsAccountConsumeModel;
use think\Db;


/**
 * 购买记录
 */
class SmsAccountBuyController extends PluginAdminBaseController
{
	/**
	 *购买记录
	 *@adminMenu(
	 *     'name'   => '购买记录',
	 *     'parent' => 'AdminIndex/index',
	 *     'display'=> true,
	 *     'hasView'=> true,
	 *     'order'  => 1000,
	 *     'icon'   => '',
	 *     'remark' => '购买记录',
	 *     'param'  => ''
	 * )
	 */
	public function index()
	{
		$param = $this->request->param();
		$search['condition1'] = 1;
		$search['keyword'] = '';
		$search['start_time'] = '';
		$search['end_time'] = '';
		if (isset($param['condition1'])) {
			$search['condition1'] = $param['condition1'];
		}
		if (isset($param['keyword'])) {
			$search['keyword'] = $param['keyword'];
		}
		if (isset($param['start_time'])) {
			$search['start_time'] = $param['start_time'];
		}
		if (isset($param['end_time'])) {
			$search['end_time'] = $param['end_time'];
		}
		$where = 1;
		if ($search['keyword']) {
			$keyword = "'%" . $search['keyword'] . "%'";
			if ($search['condition1'] == 1) {
				$where .= " and `accountid` like " . $keyword;
			} elseif ($search['condition1'] == 2) {
				$where .= " and `uid` like " . $keyword;
			} elseif ($search['condition1'] == 3) {
				$where .= " and `pay_way` like " . $keyword;
			}
		}

		if (!empty($search['start_time'])) {
			$where .= " and create_time >= '" . strtotime($search['start_time']) . "'";
		}
		if (!empty($search['end_time'])) {
			$where .= " and create_time <= '" . strtotime($search['end_time']) . "'";
		}
		$data = SmsAccountBuyModel::where($where)->order( 'create_time desc' )->paginate(20);

		$this->assign('page', $data->render()); //单独提取分页出来
		$this->assign('search', $search);
		$this->assign('data', $data);
		return $this->fetch('/sms_account_buy/index');
	}




	/**
	 * 批量删除
	 *@adminMenu(
	 *     'name'   => '批量删除',
	 *     'parent' => 'SmsAccountBuy/index',
	 *     'display'=> false,
	 *     'hasView'=> false,
	 *     'order'  => 1000,
	 *     'icon'   => '',
	 *     'remark' => '批量删除',
	 *     'param'  => ''
	 * )
	 */		
	public function batDelete(){
		$param = $this->request->param();
		if(!is_array($param['id'])){
			return zy_json_echo(false,'传参错误');
		}
		$ids = implode(',',$param['id']);

		if (SmsAccountBuyModel::destroy($ids)) {
			return zy_json_echo(true, '操作成功');
		}
		return zy_json_echo(false, '操作失败');

	}

}